home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / spline.doc < prev    next >
Text File  |  1995-03-31  |  5KB  |  130 lines

  1. (Comp.sys.handhelds) 
  2. Item: 2376 by rouben at math14.math.umbc.edu 
  3. Author: [Rouben Rostamian] 
  4.   Subj: SPLINE v2.0 
  5.   Date: Sun Mar 10 1991 
  6.  
  7. This is version 2.0 of SPLINE.  SPLINE generates a piecewise cubic and twice 
  8. continuously differentiable interpolation y(x) of a set of points (x_i,y_i), 
  9. i=1,2,...,n.  It is assumed throughout that x_1 < x_2 < ... < x_n. 
  10.  
  11. SPLINE's default action is to generate a _natural_ cubic spline, i.e., the 
  12. second derivative y'' vanishes at the end points x_1 and x_n.  The default 
  13. action of SPLINE may be modified by specifying optional switches which are 
  14. described later. 
  15.  
  16. ------- AUTHOR -------------------------------------------------------------- 
  17. Rouben Rostamian                          Telephone: (301) 455-2458 
  18. Department of Mathematics and Statistics  e-mail: 
  19. University of Maryland Baltimore County   bitnet: rostamian@umbc.bitnet 
  20. Baltimore, MD 21228,  U.S.A.              internet: rouben@math9.math.umbc.edu 
  21.  
  22. ------- INPUT --------------------------------------------------------------- 
  23. SPLINE reads its input from the stack.  The n coordinate points may be 
  24. specified in two different formats: 
  25.  
  26. THE COORDINATE-PAIRS INPUT FORMAT: 
  27. n+1: (x_1,y_1) 
  28. n:   (x_2,y_2) 
  29.      ... 
  30. 2:   (x_n,y_n) 
  31. 1:           n 
  32.  
  33. THE ARRAY INPUT FORMAT: 
  34. 2:   [ y_1 y_2 ... y_n ] 
  35. 1:           [ x_1 x_n ] 
  36.  
  37. In the ARRAY input format the interval [x_1 x_n] is automatically divided 
  38. into n equally spaced nodes.  The COORDINATE-PAIRS format is useful if 
  39. the nodes are not equally spaced. 
  40.  
  41. ----------- OUTPUT ---------------------------------------------------- 
  42. The output of SPLINE is a *program* which can be used as a user-defined 
  43. function.  The program, which is placed on level 1 of the stack, has the  
  44. following general format: 
  45.  
  46. 1: << -> X  
  47.       <<  
  48.           Description of the spline curve here 
  49.       >> 
  50.    >> 
  51.  
  52. This program may be stored in a variable, say TRY, and may be 
  53. evaluated as "TRY(X)" (algebraic mode) or as "X TRY" (RPN mode.) 
  54. TRY(X) may be plotted with the usual plotting commands. 
  55.  
  56. -------- OPTIONAL SWITCHES --------------------------------------------- 
  57. SPLINE by default imposes the natural boundary conditions y''(x_1) = y''(x_n) 
  58. = 0.  It is possible to specify instead the first derivatives a := y'(x_1) and 
  59. b := y'(x_n) as boundary conditions. For this, enter the data in one of the 
  60. two formats described before, then push the list { a b } into the level 1 of 
  61. stack. 
  62.  
  63. SPLINE can also return the first derivative y'(x) and the second derivative 
  64. y''(x) of the cubic spline interpolant.  To get these, enter data as before, 
  65. optionally enter the list { a b } from the previous paragraph, then push the 
  66. characters 'D1' into level 1 to compute y'(x), or 'D2' to compute y''(x). 
  67.  
  68. ---------- EXAMPLES -------------------------------------------------- 
  69. Example 1: 
  70.     5:  (0,0) 
  71.     4:  (1,1) 
  72.     3:  (2,4) 
  73.     2: (4,16) 
  74.     1:     4 
  75.  
  76. SPLINE returns the program: 
  77.  
  78. 1: << -> X 
  79.   << 
  80.     CASE 'X' 2 >= 
  81.       THEN '2.60869565217*(4-X)^3/2/6+6.86956521739*(X-2)+2.26086956522' 
  82.       END 'X' 1 >= 
  83.       THEN '(2.34782608696*(2-X)^3+2.60869565217*(X-1)^3)/6 
  84.                          +2.95652173913*(X-1)+.608695652173' 
  85.       END  '2.34782608696X^3/6+.608695652173*X' 
  86.     END EVAL 
  87.   >> 
  88. >> 
  89.  
  90. Example 2a: 
  91.     2: [ 0 1 0 1 0 1 0 ] 
  92.     1:           [ 0 9 ] 
  93.  
  94. The second derivative is zero at the end points. 
  95.  
  96. Example 2b: 
  97.     3: [ 0 1 0 1 0 1 0 ] 
  98.     2:           [ 0 9 ] 
  99.     1:           { 0 0 } 
  100.  
  101. The first derivative is zero at the ends.   Replacing { 0 0 } by { 1 -1 } 
  102. makes the first derivative equal 1 and -1 at the ends. 
  103.  
  104. Example 2c: 
  105.     4: [ 0 1 0 1 0 1 0 ] 
  106.     3:           [ 0 9 ] 
  107.     2:           { 0 0 } 
  108.     1:              'D1' 
  109.  
  110. Computes the first derivative y'(x) of the spline y(x) of example 2b. 
  111. Replacing 'D1' with 'D2' will computes the second derivative.   It is 
  112. instructive to save y(x), y'(x), and y''(x) into variables Y0, Y1, and Y2, 
  113. and PLOT { 'Y2(X)' 'Y1(X)' Y0(X)' } with XRANGE set to 0,9 and AUTO. 
  114.  
  115. -------- REFERENCE ----------------------------------------------------- 
  116. Stoer and Bulirsch, Numerical Analysis 
  117.  
  118. -------- REMARKS ------------------------------------------------------- 
  119. SPLINE does not use, change, create or modify any global variables. 
  120. It does not modify parts of the stack it does not own and does not alter any 
  121. system flags, although the calculator has to be in the symbolic mode for 
  122. SPLINE to operate.   It clears _user_ flags 6,7,8,9. 
  123.  
  124. -------- NOTES --------------------------------------------------------- 
  125. SPLINE V2.0 is completely different from an earlier version (no version 
  126. number) that I posted to comp.sys.handhelds a few weeks ago.  This new version 
  127. generates code which executes about 4 times faster than the previous version.  
  128. It also has many additional features.  I will not describe the differences 
  129. here because because I consider the previous version obsolete. 
  130.